home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / area2.arc / AREA2.C next >
Text File  |  1985-05-30  |  15KB  |  469 lines

  1.  /* area.c    6/2/84
  2.     Telephone area code search program
  3.         (C) 1984 Martin Smith
  4.     Compuserve 72155,1214
  5.     310 Cinnamon Oak Lane   (713) 661-1241 [Office]
  6.     Houston, Texas  77079   (713) 464-6737 [Home]
  7.  
  8.     Find area codes by entering an area code or state name on the
  9.     command line.  Multiple codes, names are permitted up to 20,
  10.     the limit set forth for C86 Computer Innovations(tm) compiler,
  11.     although your compiler may be different.
  12.     Program written for IBM-PC with PC-DOS 2.0, but no machine-specific
  13.     code is involved, other than the GETTIME routine.
  14.  
  15.     This code has been modified on 2/1/85 by the Device Driver to
  16.     (1) speed it up, (2) allow multiple names to be found, (3) add time
  17.     zones, (4) add foreign countries, (5) add new area codes.
  18.  
  19.     The table is near the top of this file to make it easier to maintain.
  20.     Area codes don't change much, but just this year in Houston our
  21.     area code was broken off from the surrounding area.
  22.     The format of the table is simple, so adding cities to the city list
  23.     or even new states or regions won't upset the program if a few easy
  24.     rules are followed:
  25.  
  26.     1) The table format is one array of string pointers.
  27.     2) A state name consists of a two character postal abbreviation,
  28.        like ca for California, and then the actual name,
  29.        a)  All data on this line is lowercase. A multiple word name,
  30.            like New Jersey, would be entered as "njnew*jersey" , .
  31.            This prevents argv from making two arguments out of the name.
  32.     3) An area code is the three digit code, followed by whatever text.
  33.        a)  As many area codes, cities as you want are ok.
  34.        b)  Note the program depends on a state name not beginning with
  35.            a number.  When a numeric code is searched and found, the
  36.            program goes back to the first non-numeric for the state name.
  37.     4) All entries need to be enclosed in quotes (") and followed by a
  38.        comma.
  39.     5) Countries have the same form as states.
  40.     6) Time zone follow the state name as (+n) for n hours after Eastern,
  41.            (-n) for n hours before Eastern, and (\t..) to add an extra 1/2
  42.            hour.
  43.  */
  44.  
  45. #include "stdio.h"
  46. #include "ctype.h"
  47. #include "dos.h"
  48. int tme[10];    /* time date array */
  49. areacode(s,x)
  50. char *s;
  51. int x;
  52. {
  53. unsigned strlen();
  54.  
  55. static char *area[] =
  56.  
  57. {
  58. "alalabama(-1)",    "205 All pts",
  59. "akalaska(-5)",    "907 All pts",
  60. "azarizona(-2)",     "602 All pts",
  61. "ararkansas(-1)",     "501 All pts",
  62. "cacalifornia(-3)" ,
  63.     "209 Fresno" , "213 Los Angeles" , "408 San Jose" ,
  64.     "415 San Francisco" ,  "619 San Diego" ,  "707 Santa Rosa" ,
  65.     "714 Orange" ,  "805 Bakersfield" , "916 Sacramento" ,
  66. "cncanada - pacific(-3)" ,
  67.     "604 British Columbia:Vancouver" ,
  68. "cncanada - mountain(-2)" ,
  69.     "306 Saskatchewan:" ,
  70.     "403 Alberta: Calgary, Edmonton" ,
  71. "cncanada - central(-1)" ,
  72.     "204 Manitoba:" ,
  73. "cncanada - eastern(0)" ,
  74.     "416 Ontario: Toronto, Mississauga" ,
  75.     "418 Quebec: Quebec" ,
  76.     "514 Quebec: Montreal" ,
  77.     "519 Ontario: London" ,
  78.     "613 Ontario: Ottawa" ,
  79.     "705 West Ontario" ,
  80.     "807 East Ontario" ,
  81.     "819 NW Quebec" ,
  82. "cncanada - atlantic(+1)" ,
  83.     "709 Newfoundland:" ,
  84.     "506 New Brunswick: Costa Rica" ,
  85.     "902 Nova Scotia & Prince Edward Island:" ,
  86. "cocolorado(-2)"   , "303 All pts" ,
  87. "ctconnecticut(0)" , "203 All pts" ,
  88. "dedelaware(0)"   , "302 All pts" ,
  89. "dcdistrict*of*columbia(0)" , "202 Washington" ,
  90. "flflorida(0)" ,
  91.     "305 Miami, Key West, Ft. Lauderdale" ,
  92.     "813 Ft. Myers, Winter Haven" , "904 Jacksonville" ,
  93. "gageorgia(0)" ,
  94.     "404 Atlanta, Rome" , "912 Waycross" ,
  95. "hihawaii(-5)",    "808 All pts" ,
  96. "ididaho(-2)",    "208 All pts" ,
  97. "ilillinois(-1)" ,
  98.     "217 Springfield" , "309 Peoria" ,  "312 Chicago, Aurora, Waukegan" ,
  99.     "618 Alton, Mt. Vernon" , "815 Rockford" ,
  100. "inindiana(0)" ,
  101.     "219 Gary, South Bend, Warsaw" ,
  102.     "317 Indianapolis, Kokomo" , "812 Evansville" ,
  103. "iaiowa(-1)" ,
  104.     "319 Dubuque" , "515 Des Moines" , "712 Council Bluffs" ,
  105. "kskansas(-1)" ,
  106.     "316 Wichita, Dodge City" ,
  107.     "913 Topeka, Lawrence, Manhattan, Salina" ,
  108. "kykentucky(0)" ,
  109.     "502 Louisville, Frankfort, Paducah, Shelbyville" , "606 Winchester" ,
  110. "lalouisiana(-1)" ,
  111.     "504 Baton Rouge, New Orleans" , "318 Lake Charles" ,
  112. "memaine(0)",    "207 All pts" ,
  113. "mdmaryland(0)",    "301 All pts" ,
  114. "mamassachusetts(0)" ,
  115.     "413 Springfield" ,
  116.     "617 Boston, New Bedford, Plymouth, Worchester" ,
  117. "mxmexico(+1)" ,
  118.     "905 Mexico City" , "706 NW Mexico" ,
  119. "mimichigan(0)" ,
  120.     "313 Detroit, Ann Arbor, Flint" ,
  121.     "616 Battle Creek, Grand Rapids, Kalamazoo" ,
  122.     "517 Lansing" , "906 Escanaba" ,
  123. "mnminnesota(-1)" ,
  124.     "218 Duluth" , "612 Minneapolis, St. Paul" , "507 Rochester" ,
  125. "msmississippi(-1)",    "601 All pts" ,
  126. "momissouri(-1)" ,
  127.     "314 St. Louis, Cape Girardeau, Columbia, Fulton, Hannibal, \n\tJefferson City, Mexico, Poplar Bluff, Rolla" ,
  128.     "417 Joplin, Springfield" ,
  129.     "816 Belton, Independence, Kansas City, Marshall, St. Joseph, Sedalia" ,
  130. "mtmontana(-2)",    "406 All pts" ,
  131. "nenebraska(-1)" ,
  132.     "402 Omaha, Lincoln" , "308 North Platte" ,
  133. "nvnevada(-3)",    "702 All pts" ,
  134. "nhnew*hampshire(0)",    "603 All pts" ,
  135. "njnew*jersey(0)" ,
  136.     "201 Newark, Hackensack, New Brunswick, Patterson" ,
  137.     "609 Atlantic City, Camden, Trenton" ,
  138. "nmnew*mexico(-2)",    "505 All pts" ,
  139. "nynew*york(0)" ,
  140.     "212 New York City" , "315 Syracuse" , "518 Albany, Schenectady" ,
  141.     "607 Binghamton" , "716 Buffalo, Niagara Falls, Rochester" ,
  142.     "718 New York City" ,  "914 White Plains" ,
  143. "ncnorth*carolina(0)" ,
  144.     "704 Charlotte, Salisbury" ,
  145.     "919 Greenville, Raleigh, Winston-Salem" ,
  146. "ndnorth*dakota(-1)",    "701 All pts" ,
  147. "ohohio(0)" ,
  148.     "216 Akron, Cleveland, Youngstown" ,
  149.     "419 Toledo" ,
  150.     "513 Cincinnati, Dayton" , "614 Columbus" ,
  151. "okoklahoma(-1)" ,
  152.     "405 Oklahoma City, Enid, Norman, Ponca City, Stillwater" ,
  153.     "918 Tulsa, Bartlesville, McAlester, Muskogee" ,
  154. "ororegon(-3)",    "503 All pts" ,
  155. "papennsylvania(0)" ,
  156.     "215 Philadelphia, Allentown" ,
  157.     "412 Pittsburgh" , "717 Harrisburg, Scranton" ,  "814 Erie" ,
  158. "prpuerto*rico(0)"  ,
  159. "809 Anguilla, Antigua, Bahamas, Barbados, Bermuda, Cayman Islands, \n\tDominican Republic, Jamaica, St. Lucia, Trinidad" ,
  160. "rirhode*island(0)",    "401 All pts" ,
  161. "scsouth*carolina(0)",    "803 All pts" ,
  162. "sdsouth*dakota(-1)",    "605 All pts" ,
  163. "tntennessee(-1)" ,
  164.     "615 Nashville, Chattanooga" , "901 Memphis" ,
  165. "txtexas(-1)" ,
  166.     "214 Dallas, Ennis, Greenville, Jefferson, Longview, Sherman, Tyler" ,
  167.     "409 Bay City, Beaumont, Bryan, College Station, Galveston, Huntsville" ,
  168.     "512 Austin, Brownsville, Corpus Christi, Del Rio, Eagle Pass, \n\tLaredo, McAllen, San Antonio, Victoria" ,
  169.     "713 Houston, Baytown, Pasadena" ,
  170.     "806 Amarillo, Dalhart, Lubbock" ,
  171.     "817 Fort Worth, Denton, Temple, Waco, Wichita Falls" ,
  172.     "915 Abilene, Alpine, Big Spring, El Paso, Midland, Odessa" ,
  173. "ututah(-2)",    "801 All pts" ,
  174. "vtvermont(0)",    "802 All pts" ,
  175. "vivirgin*islands(0)",    "809 All pts" ,
  176. "vavirginia(0)" ,
  177.     "703 Roanoke, Winchester" ,
  178.     "804 Charlottesville, Newport News, Norfolk, Richmond" ,
  179. "wawashington(-3)" ,
  180.     "206 Seattle, Olympia, Vancouver" , "509 Walla Walla" ,
  181. "  wide area"   , "800 All pts" ,
  182. "wvwest*virginia(0)",    "304 All pts" ,
  183. "wiwisconsin(-1)" ,
  184.     "414 Milwaukee, Green Bay, Racine" ,
  185.     "608 Madison" , "715 Wausau" ,
  186. "wywyoming(-2)",    "307 All pts" ,
  187. "--algeria(+6)"         , "213 All",
  188. "--argintina(+2)"        , "54- All",
  189. "--australia(+15)"        , "61- Adelaide, Melbourne, Newcastle, South perth, Spring hill, Sydney",
  190. "--austria(+6)"         , "43- Vienna",
  191. "--barbados(+1)"        , "809 All",
  192. "--belgium(+6)"         , "32- Brussels",
  193. "--bolivia(+1)"         , "591 All",
  194. "--braddon(0)"            , "616 All",
  195. "--brazil(+2)"            , "55- All",
  196. "--cameroon(+6)"        , "237 All",
  197. "--chile(+1)"            , "056 All",
  198. "--columbia(0)"         , "287 bogota",
  199. "--costa rica(-1)"        , "506 All",
  200. "--cyprus(+7)"            , "357 All",
  201. "--denmark(+6)"         , "45- Copenhagen",
  202. "--egypt(+7)"            , "20- All",
  203. "--el salvador(-1)"        , "503 All",
  204. "--equador(+0)"         , "593 Ecuador",
  205. "--ethiopia(+8)"        , "251 All",
  206. "--finland(+7)"         , "358 Helsinki",
  207. "--france(+6)"            , "33- All",
  208. "--french antilles(+1)"     , "596 All",
  209. "--french polyesia(-5)"     , "589 All",
  210. "--fuji(+17)"            , "679 All",
  211. "--gabon(+6)"            , "241 All",
  212. "--germ dem. rep.(+6)"        , "37- All",
  213. "--germ fed rep of(+6)"     , "49- Duesseldorf, frankfurt, hamburg, hannover, muenchen, \n\tnberg, stuttart",
  214. "--greece(+7)"            , "030 All",
  215. "--guam(+15)"            , "671 All",
  216. "--guantanamo(+0)"        , "53- All",
  217. "--guatemala(-1)"        , "502 All",
  218. "--guatemala(0)"        , "502 All",
  219. "--guyana(\t+2)"         , "592 All",
  220. "--haiti(+0)"            , "509 All",
  221. "--haiti(-3)"            , "509 All",
  222. "--honduras(-1)"        , "504 All",
  223. "--hong kong(+13)"        , "852 All",
  224. "--iceland(+5)"         , "354 All",
  225. "--india(\t+10)"         , "242 All",
  226. "--indonesia(+12)"        , "062 All",
  227. "--iran(\t+8)"            , "98- All",
  228. "--iraq(+8)"            , "964 All",
  229. "--ireland(+5)"         , "353 Dublin",
  230. "--isreal(+7)"            , "972 All",
  231. "--italy(+6)"            , "39- Bologna, firenze, milano, padova, rome, tourin",
  232. "--ivory coast(+5)"        , "225 All",
  233. "--japan(+14)"            , "81- gyoda, nagoya, osaka, tokyo",
  234. "--jordan(+7)"            , "431 All",
  235. "--kenya(+8)"            , "254 All",
  236. "--korea(+14)"            , "82- All",
  237. "--kuwait(+8)"            , "965 All",
  238. "--lebenon(+7)"         , "961 All",
  239. "--liberia(+5)"         , "231 All",
  240. "--libya(+7)"            , "218 All",
  241. "--liechtenstein(+6)"        , "41- All-shared",
  242. "--luxembourg(+6)"        , "352 All",
  243. "--malawi(+7)"            , "265 All",
  244. "--malaysia(+13)"        , "60- All",
  245. "--mexico(+1)"            , "052 All",
  246. "--monaco(+6)"            , "33- All-shared with France",
  247. "--morocco(+5)"         , "212 All",
  248. "--netherlands antilles(+1)"    , "599 All",
  249. "--netherlands(+6)"        , "31- Amsterdam, badhoevedorp, rijswijk, zwolle",
  250. "--new caledonia(+16)"        , "687 All",
  251. "--new zealand(+17)"        , "64- Auckland, Wellington",
  252. "--nicaragua(-1)"        , "505 All",
  253. "--nigeria(+6)"         , "234 All",
  254. "--norway(+6)"            , "47- Oslo",
  255. "--oman(+9)"            , "968 All",
  256. "--pakistan(+10)"        , "92- All",
  257. "--panama(+0)"            , "507 All",
  258. "--paraguay(+1)"        , "595 All",
  259. "--peru(+0)"            , "51- All",
  260. "--phillipines(+13)"        , "63- All",
  261. "--portugal(+5)"        , "351 All",
  262. "--quatar(+9)"            , "974 All",
  263. "--romania(+7)"         , "40- All",
  264. "--saudia arabia(+8)"        , "966 All",
  265. "--senegal(+5)"         , "221 All",
  266. "--singapore(+13)"        , "65- All",
  267. "--south africa(+7)"        , "27- Johannesburg",
  268. "--spain(+6)"            , "34- Barcelona, madrid",
  269. "--sri lanka(\t+10)"        , "94- All",
  270. "--st denis"            , "331 All",
  271. "--suriname(\t+1)"        , "597 All",
  272. "--sweden(+6)"            , "46- Gothenborg, malmoe, stockholm, basle, bern, lausanne, zurich",
  273. "--taiwan(+13)"         , "886 All",
  274. "--thailand(+12)"        , "66- All",
  275. "--tunisia(+6)"         , "216 All",
  276. "--turkey(+8)"            , "90- All",
  277. "--united arab emirates(+9)"    , "971 arabia",
  278. "--united kingdom(+5)"        , "44- birmingham, bristol, hounslow, leeds, london, \n manchester, middlesex, paisley",
  279. "--uruguay(+2)"         , "598 All",
  280. "--vatican city(+2)"        , "39- All-shared with Italy",
  281. "--venezuela(+1)"        , "58- codata",
  282. "--yugoslavia(+6)"        , "38- All",
  283. NULL  } ;
  284.  
  285.     int i,j,found;
  286.     unsigned k;
  287.     char *t;
  288.  
  289.     found=0;
  290.  
  291. if (x==2)   /* a number area code */
  292.     {
  293.     for (i=0; area[i] != NULL; i++)
  294.        if (strncmp(area[i],s,3)==0)  /* test for match */
  295.         {
  296.         for (j=i-1; isdigit(*area[j]) ; --j)  /* then go back for state */
  297.             ;
  298.         stprint(area[j]);       /* special print out for state name */
  299.         putchar('\n');
  300.         printf("    %s.\n\n",area[i]);
  301.         found=-1;
  302.         }
  303.     }
  304.  
  305. else   /* state name or two letter code is input */
  306.     {
  307.     for (i=0; s[i] != '\0'; i++)    /* make everything lowercase */
  308.         s[i]=tolower(s[i]);
  309.     k=strlen(s);
  310.     for (i=0; area[i] != NULL; i++)
  311.         if (isdigit(*area[i])==0)
  312.             if (strncmp(area[i]+2,s,k) == 0 ||
  313.              (k==2 && strncmp(s,area[i],2)==0) || s[0]=='*')
  314.                 {
  315.                 found = -1;
  316.                 allprint(&area[i]);
  317.                 }
  318.     }
  319. if (found==0)
  320.     printf("Not found, %s.\n\n",s);
  321. } /* end areacode() */
  322.  
  323.  /* special printout for state name */
  324. stprint(s)
  325. char s[];
  326. {
  327.     int i,n;
  328.     putchar(toupper(s[0]));
  329.     putchar(toupper(s[1]));
  330.     printf("  ");
  331.     putchar(toupper(s[2]));
  332.     for (s+=3;  *s != '\0' &&  *s != '('  ; s++)
  333.         if (*s=='*')
  334.             {
  335.             putchar(' ');s++;
  336.             putchar(toupper(*s));
  337.             }
  338.         else
  339.             putchar(*s);
  340.     if ((*s++)=='(')
  341.         {
  342.         printf(" (");
  343.         i=(*s=='\t') ? 30 : 0;
  344.         otime( tme[1]+satoi(s) , tme[2]+i );
  345.         putchar(')');
  346.         }
  347.     printf(" area codes: ");
  348. } /* end stprint */
  349.  
  350.  /* print state and cities */
  351. allprint(area)
  352. char *area[];
  353. {
  354.     int j;
  355.     stprint(area[0]);
  356.     putchar('\n');
  357.     for (j=1; isdigit(*area[j]) ; j++)
  358.         printf("    %s.\n",area[j]);
  359.     putchar('\n');
  360. } /* end allprint() */
  361.  
  362.  
  363.  /* integer convert to number */
  364. int satoi(s)
  365. char s[];
  366. {
  367.     int i, n, sign;
  368.  
  369.     for (i=0; *s==' ' || *s=='\n' || *s=='\t'; s++)
  370.         ;  /* skip white space */
  371.  
  372.     sign = 1;
  373.     if (*s == '+' || *s == '-')
  374.         sign = (*s++ == '+') ? 1 : -1;
  375.     for (n=0; *s >= '0' && *s <= '9'; s++)
  376.         n = 10 * n + *s - '0';
  377.     return(sign * n);
  378.  
  379. } /* end satoi */
  380.  
  381. /* limited string compare */
  382. int strncmp(x,y,n)
  383. char *x, *y;
  384. int n;
  385. {
  386.     int c;
  387.     while (n--) {
  388.         if (c=*x-*y++) return (c);
  389.         if (*x++=='\0') return (0);
  390.         }
  391.     return (0);
  392. }
  393.  
  394. otime(h,m)
  395. int h,m;
  396. {
  397.     static char s;
  398.     while (m>60)
  399.         {
  400.         m-=60;
  401.         h++;
  402.         }
  403.     s=( ((h+24)%24) < 12 ) ? 'a' : 'p';
  404.     h=(h+23) %12 +1;
  405.     printf("%02u:%02u %cm", h,m,s );
  406. } /* end otime */
  407.  
  408. gettime(tme)
  409. int tme[];
  410. {
  411.     int intno = 0x21;        /* interrupt # */
  412.     union REGS inregs;        /* in reg */    
  413.     union REGS outregs;        /* out reg */
  414.  
  415.     inregs.h.ah = 0x2C;        /* svc # */
  416.     int86(intno,&inregs,&outregs);
  417.     tme[1] = outregs.h.ch;        /* hrs */
  418.     tme[2] = outregs.h.cl;        /* min */
  419.     tme[3] = outregs.h.dh;        /* sec */
  420.     tme[4] = outregs.h.dl;        /* 100ths */
  421.  
  422.     inregs.h.ah = 0x2A;        /* svc # */
  423.     int86(intno,&inregs,&outregs);
  424.     tme[5] = outregs.h.al;        /* (0-6) (sun-sat) */
  425.     tme[6] = outregs.x.cx;        /* yr */
  426.     tme[7] = outregs.h.dh;        /* mo */
  427.     tme[8] = outregs.h.dl;        /* day */
  428.      return;
  429. } /* end gettime() */
  430.  
  431. main(argc,argv)
  432. int  argc;
  433. char *argv[];
  434. {
  435.     int i,satoi();
  436.     static char *dayno[] = {"Sun", "Mon", "Tue", "Wed", "Thurs", "Fri", "Sat"};
  437.     puts("   ** Area Code Finder **");
  438.     puts("    (C) Marty Smith 1983 - Changed 1/30/85 by DD");
  439.     gettime(tme);
  440.     printf("    ");
  441.     otime(tme[1],tme[2]);
  442.     printf(" %s %d/%d/%d\n\n", dayno[tme[5]], tme[7],tme[8],tme[6]);
  443.     if (argc==1)
  444.         {
  445.     puts("Program searches for telephone area codes,");
  446.     puts("   Use:  AREA xxx xxx xxx ...\n");
  447.     puts("   where xxx can be:");
  448.     puts("     -An Area Code (like 914).");
  449.     puts("     -A two letter state postal code (as in TX for Texas).");
  450.     puts("     -The first few letters of the state name (as in MASS).");
  451.     puts("     -A two word state names with * (as in New*Jersey).");
  452.     puts("     -A foreign 2 digit area code with - (like 33- for France).");
  453.     puts("     -A +n or -n for your timezone, relative to Eastern");
  454.     puts("          (for example, Calif residents use 'AREA -3 ...').\n");
  455.     puts("   Enter 'AREA *' for a list of all Area Codes.");
  456.         }
  457.  
  458.     else
  459.         for (i=1; i < argc; ++i)
  460.             if (*argv[i]=='+' || *argv[i]=='-')
  461.                 tme[1]-=satoi(argv[i]);
  462.             else
  463.             if (isdigit(*argv[i])==0)
  464.                 areacode(argv[i],1);
  465.             else
  466.                 areacode(argv[i],2);
  467.  
  468. } /* end main() */
  469.